package databaseVersionControl.infra.system;

import databaseVersionControl.domain.db.Column;
import databaseVersionControl.domain.db.DataType;
import databaseVersionControl.domain.db.SequenceComponent;
import databaseVersionControl.domain.db.TableComponent;
import databaseVersionControl.infra.annotation.DatabaseScript;
import databaseVersionControl.infra.annotation.ScriptAuthor;
import databaseVersionControl.infra.annotation.ScriptOrder;
import databaseVersionControl.infra.annotation.ScriptSystem;
import databaseVersionControl.infra.connection.DataBaseProxy;
import databaseVersionControl.infra.script.Script;

@DatabaseScript(name="Base")
public class SystemBase {

	@ScriptSystem
	@ScriptOrder(1)
	@ScriptAuthor("Robson e Michel Ruiz")
	public SequenceComponent createDVCSequence() {
		return new Script().create().sequence(DataBaseProxy.SEQUENCE_NAME).incrementBy(1).initialValue(1).ifNotExists();
	}

	@ScriptSystem
	@ScriptOrder(2)
	@ScriptAuthor("Robson e Michel Ruiz")
	public TableComponent createVersionTable() {
		return new Script().create().table("installed_scripts").defineColumns(
				new Column("id").type(DataType.LONG).primaryKey().notNull(),
				new Column("class_name").type(DataType.STRING).size(50).notNull(),
				new Column("number").type(DataType.LONG)).ifNotExists();
	}
	
}